package com.core.website.api;

import com.core.website.common.Result;
import com.core.website.common.ResultUtil;
import com.core.website.entity.CoreDutyRecordInfo;
import com.core.website.entity.CoreDutyRecordMonitoring;
import com.core.website.entity.User;
import com.core.website.service.CoreDutyRecordMonitoringService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dutyRecordMonitoringApi")
public class CoreDutyRecordMonitoringController {
    @Autowired
    CoreDutyRecordMonitoringService coreDutyRecordMonitoringService;

    @GetMapping("/list")
    public Result getList(String contentId){
        List<CoreDutyRecordMonitoring> list = coreDutyRecordMonitoringService.selectCoreDutyRecordMonitoringList(contentId);
        return ResultUtil.success(list);
    }
    @PostMapping("/add")
    public Result add(@RequestBody CoreDutyRecordMonitoring dutyRecordMonitoring){

        User subject = (User) SecurityUtils.getSubject().getPrincipal();
        if(null==subject){
            return ResultUtil.error(-1000,"用户未登录");
        }
        String result=coreDutyRecordMonitoringService.insertCoreDutyRecordMonitoring(dutyRecordMonitoring);
        return ResultUtil.success(result);
    }
    @PostMapping("/edit")
    public Result edit(@RequestBody CoreDutyRecordMonitoring dutyRecordMonitoring){

        User subject = (User) SecurityUtils.getSubject().getPrincipal();
        if(null==subject){
            return ResultUtil.error(-1000,"用户未登录");
        }
        int result=coreDutyRecordMonitoringService.updateCoreDutyRecordMonitoring(dutyRecordMonitoring);
        return ResultUtil.success(result);
    }
    @GetMapping("/delete")
    public Result delete(String id){

        User subject = (User) SecurityUtils.getSubject().getPrincipal();
        if(null==subject){
            return ResultUtil.error(-1000,"用户未登录");
        }
        int result = coreDutyRecordMonitoringService.deleteCoreDutyRecordMonitoring(id);
        return ResultUtil.success(result);
    }

    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") String id)
    {
        return ResultUtil.success(coreDutyRecordMonitoringService.selectCoreDutyRecordMonitoringById(id));
    }



}
